<template>
  <div>
    <div>
      <el-row class="nav">
        <span class="font-weight">{{ orderItem.title }}</span>
        <button @click="exportOrder"
                type="button"
                v-if="btnStates.EWS_order_export_010"
                class="el-button el-button--primary el-button--medium h30Btn fr export">
          导出
        </button>
        <button @click="createForm('新建')"
                type="button"
                v-if="btnStates.EWS_create_order_008"
                class="el-button el-button--primary el-button--medium h30Btn fr">
          新建
        </button>
        <button @click="mergeOrder"
                type="button"
                v-if="btnStates.EWS_merge_order_025"
                class="el-button el-button--primary el-button--medium h30Btn fr">
          合并
        </button>
      </el-row>
      <el-divider></el-divider>
      <!-- 搜索部分 -->
      <el-row>
        <el-col :span="22">
          <avue-form v-model="form"
                     v-loading='srLoading'
                     :option="option">
            <template slot-scope="scope"
                      slot="current_handler_name">
              <el-row style="display: flex">
                <el-col :span="10">
                  <el-select v-model="current_handler_name.type"
                             clearable
                             style="width: 30%"
                             @change="getSecondDataList"
                             placeholder="请选择">
                    <el-option v-for="item in handleTypeList"
                               :key="item.value"
                               :label="item.label"
                               :value="item.value">
                    </el-option>
                  </el-select>
                </el-col>
                <el-col :span="14">
                  <!-- 部门 -->
                  <el-cascader v-if="
                      current_handler_name.type &&
                      current_handler_name.type == 'dept'
                    "
                               expand-trigger="hover"
                               :options="userValueList"
                               placeholder="请选择"
                               clearable
                               filterable
                               :props="{
                      value: 'value',
                      label: 'label',
                      children: 'children',
                      multiple: false,
                      checkStrictly: true,
                    }"
                               v-model="current_handler_name.value"
                               @change="handleChange">
                  </el-cascader>
                  <!-- 员工 -->
                  <el-select v-model="current_handler_name.value"
                             v-if="
                      current_handler_name.type &&
                      current_handler_name.type == 'user'
                    "
                             clearable
                             filterable
                             :multiple="false"
                             style="width: 70%"
                             placeholder="请选择">
                    <el-option v-for="item in userValueList"
                               :key="item.value"
                               :label="item.label"
                               :value="item.value">
                    </el-option>
                  </el-select>
                </el-col>
              </el-row>
            </template>
          </avue-form>
        </el-col>
        <el-col :span="2">
          <el-button size="mini"
                     class="el-button el-button--primary h30Btn searchBtn"
                     @click="handleSearch">查询</el-button>
          <el-button size="mini"
                     class="el-button el-button--primary h30Btn searchBtn"
                     @click="resart">重置</el-button>
          <el-button size="mini"
                     v-if="advanceField.length>0"
                     class="el-button el-button--primary h30Btn searchBtn"
                     @click="advanceFilterFun">高级筛选</el-button>
        </el-col>
      </el-row>
      <avue-crud :option="orderOption"
                 @selection-change="handleSelectionChange"
                 @filter-change="filterChange"
                 @select="pinSelect"
                 ref="multipleTable"
                 :data="tableData">
        <template slot="id"
                  slot-scope="scope">
          <el-badge value="超时"
                    class="item"
                    v-if="scope.row.isTimeOut == 'Y'">
            <el-button class="order_num"
                       type="text"
                       @click="orderDetails(scope.row)">{{ scope.row.id }}</el-button>
          </el-badge>
          <el-button class="order_num"
                     v-else
                     type="text"
                     @click="orderDetails(scope.row)">{{ scope.row.id }}</el-button>
        </template>
        <template slot-scope="scope"
                  slot="menu"
                  v-if="itemType === '5'"
                  style="width: 100px">
          <el-button type="text"
                     v-if="scope.row.voiceKeyId"
                     class="order_num"
                     @click="playAudio(scope.row.voiceKeyId)">录音播放</el-button>
          <el-button type="text"
                     class="order_num"
                     @click="checked(scope.row.customField.CONS_NO||scope.row.customField.consNo||'')">查看</el-button>
        </template>
      </avue-crud>
      <el-row> </el-row>
      <el-row class="paging-foot page-foot-spacing"
              :gutter="20">
        <el-col :span="14"
                style="white-space: nowrap; display: flex">
          <span class="color-select">批量操作</span>
          <span class="select-number">（已选中{{ selectAllIdLength }}条）</span>
          <el-button @click="deleteSelect"
                     v-if="btnStates.EWS_order_delete_027"
                     type="button"
                     class="el-button el-button--primary el-button--medium h30Btn btn30-default">删除</el-button>
          <el-button @click="closeSelect"
                     v-if="btnStates.EWS_order_close_028"
                     type="button"
                     class="el-button el-button--primary el-button--medium h30Btn btn30-default">关闭</el-button>
        </el-col>
        <el-col :span="10">
          <div class="fr">
            <el-pagination background
                           class="el-pagination-style"
                           v-show="orderPage.total > 0"
                           @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="orderPage.page"
                           :page-sizes="orderPage.pageSizes"
                           :page-size="orderPage.pageSize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="orderPage.total"></el-pagination>
          </div>
        </el-col>
      </el-row>
    </div>
    <audioDialog v-show="audioBlock"
                 :voiceDataInfo="voiceDataInfo"
                 @audioShow="closeDialog"
                 ref="audioMP3"></audioDialog>
  </div>
</template>
<script>
// https://devcc.egooccs.com/upload/%252Fdata1%252Fvoice%252Fdefault%252F2020-11-24%252Fdms3Dm8xbD.mp3
// import { serOption, advanceFilterOption } from "@/common/commonOption.js";
import common from "@/common/common.js";
import { selectByCode } from "@/api/customField";
import audioDialog from "@/views/orderDataList/orderDialog/audioDialog";
import { getVoiceInfo } from '@/api/workOrderController';

import {
  getSelect,
  selectAllWorkOrderStatusName,
  selectAllWorkOrderTypeName,
  writeWithHead,
  deleteBatch,
  closeBatch,
  getUserListByWorkOrderTypeNodeId,
  advancedFilterData
} from "@/api/workOrderController";
export default {
  props: ['orderTypeName', 'orderItem'],
  data () {
    return {
      lists: [],
      changeLists: [],
      origin: -1, // 这里给一个变量作为起点
      pin: false, // 这里给一个变量，默认为false，不按住
      basicField: window.FilterFuns && window.FilterFuns.basicFilterOption({}, {}).column || [],
      advanceField: window.FilterFuns && window.FilterFuns.advanceFilterOption({}, {}).column || [],
      searchBasicOption: {},
      searchAdvanceOption: [],
      itemType: window.CONFIG.itemType,
      orderPage: {
        pageSizes: [10, 20, 30, 40, 100],
        total: 0,
        pageSize: 10,
        page: 1,
      },
      advanceFilter: [],
      advanceFilterData: [],
      orderOptionData: {
        menuWidth: 100,
        selection: true,
        selectClearBtn: false,
        reserveSelection: true,
        page: false,
        align: "center",
        menuAlign: "center",
        addBtn: false,
        border: true,
        filterBtn: false,
        menu: false,
        menuBtn: false,
        refreshBtn: false,
        columnBtn: false,
        overHidden: false,
        column: [],
        delBtn: false,
        editBtn: false,
      },

      btnStates: window.CONFIG.btnState,
      form: {},
      forms: {
        nodeVal: "",
        nodes: [],
        userType: "",
        userTypes: [],
        userValue: [],
        userOptions: [],
        seviceType: "",
        orderType: ""
      },
      customField: {},
      selectAllIdLength: 0,
      loading: true,
      tableData: [],
      multipleSelection: [],
      workOrderFilterId: 2,
      field: "",
      exportWorkOrderIdList: [],
      sortTag: 1,
      workOrderTypeId: this.$store.state.workOrderTypeId,
      currentWorkOrderNodeId: 0,
      jsonData: {
        list: [
          {
            type: "input",
            name: "单行文本",
            icon: "icon-input",
            options: {
              width: "100%",
              defaultValue: "",
              required: false,
              dataType: "string",
              pattern: "",
              placeholder: "",
              remoteFunc: "func_1540908864000_94322"
            },
            key: "1540908864000_94322",
            model: "input_1540908864000_94322",
            rules: [
              {
                type: "string",
                message: "单行文本格式不正确"
              }
            ]
          }
        ],
        config: {
          labelWidth: 100,
          labelPosition: "top",
          size: "small"
        }
      }, // 数据模板
      nodeContent: {},
      flowButtonArr: [],
      buttonInfo: "",
      showData: "",
      // 特制字段
      handleTypeList: [
        { value: "dept", label: "部门" },
        { value: "user", label: "员工" }
      ],
      userValueList: [],
      current_handler_name: {
        type: "",
        value: ""
      },
      // 搜索页面数据源字段表
      workOrderStatusId_list: [],
      business_type_list: [],
      priority_list: [],
      source_list: [],
      order_type_list: [],
      handle_institution_list: [],
      voiceDataInfo: {
        callUUID: '',
      },
      audioBlock: false
    };
  },
  components: {
    audioDialog
  },
  activated () {
    if (this.$route.meta.isUseCache) {
      // if (this.itemType == "3") {
      this.handleSearch();
      // } else {
      //   this.tableData = [];
      // }
    } else {
      this.$route.meta.isUseCache = false;
    }
  },
  beforeRouteLeave (to, from, next) {
    if (to.name === 'orderTable') {
      to.meta.isUseCache = true
    } else {
      to.meta.isUseCache = false
    }
    next()
  },
  computed: {
    srLoading () {
      if (!window.FilterFuns) {
        this.loading = true
      } else {
        this.loading = false
        this.getSearchOption()
      }
      return this.loading
    },
    // eslint-disable-next-line vue/return-in-computed-property
    option () {
      let valueArray = {}
      let totalField = this.basicField.concat(this.advanceField)
      for (var i in totalField) {
        if (totalField[i].type === 'select' || totalField[i].type === 'cascader') {
          valueArray[totalField[i].prop] = this[totalField[i].prop + '_list']
        }
      }
      this.getSearchOption()
      let options = this.searchBasicOption
      options.column && options.column.push(...this.searchAdvanceOption)
      return options;
    },

    userId () {
      return this.$store.getters.userId;
    },
    orderOption () {
      if (this.itemType === '5') {
        this.orderOptionData['menu'] = true
        return this.orderOptionData
      } else {
        return this.orderOptionData
      }
    },
    typeIdChange () {
      return this.$store.state.orderTypeId;
    },
    // workOrderTypeIdFun () {
    //   return this.$store.state.workOrderTypeId;
    // }
  },
  watch: {
    userId (newVal, oldVal) {
      this.getCustomField()
      this.handleSearch();
      this.advancedFilterData();
    },
    // workOrderTypeIdFun (newVal, oldVal) {
    //   this.workOrderTypeId = newVal;
    // },
    jsonData (newVal, oldVal) {
      this.jsonData = newVal;
    },
    $route (to, from) {
      // if (from.name !== "formDetails" && to.name === "orderTable") {
      //   this.advanceFilter = []
      //   this.resart();
      //   // this.handleSearch();
      //   this.advancedFilterData();
      //   this.getCustomField()
      // }
    }
  },
  created () {
  },
  mounted () {
    // if (window.CONFIG.test) {
    this.getCustomField()
    this.handleSearch();
    this.advancedFilterData();
    // }
    window.addEventListener('keydown', code => { // 这个是获取键盘按住事件
      // console.log(code) // 这个是你按住键盘打印出键盘信息，在浏览器中自行查看
      if (code.keyCode === 16 && code.shiftKey) { // 判断是否按住shift键，是就把pin赋值为true
        this.pin = true
      }
    })
    window.addEventListener('keyup', code => { // 这个是获取键盘松开事件
      if (code.keyCode === 16) { // 判断是否松开shift键，是就把pin赋值为false
        this.pin = false
        if (this.lists.length > 2) {
          this.exportWorkOrderIdList = this.lists
        } else {
          this.exportWorkOrderIdList = this.changeLists
        }
        this.selectAllIdLength = this.exportWorkOrderIdList.length
      }
    })
  },
  destroyed () {
    window.removeEventListener('keydown', code => {
      if (code.keyCode === 16 && code.shiftKey) {
        this.pin = true
      }
    }, false)
    window.removeEventListener('keyup', code => {
      if (code.keyCode === 16) {
        this.pin = false
      }
    }, false)
  },
  methods: {
    // 这里是select事件开始
    pinSelect (item, row) {
      const data = this.tableData // 获取所有数据
      const origin = this.origin // 起点数 从-1开始
      const endIdx = row.index // 终点数
      if (this.pin && item.includes(data[origin])) { // 判断按住
        // this.$refs.multipleTable.selectClear()
        const sum = Math.abs(origin - endIdx) + 1// 这里记录终点
        const min = Math.min(origin, endIdx)// 这里记录起点
        let i = 0

        while (i < sum) {
          const index = min + i
          this.$refs.multipleTable.toggleRowSelection(data[index], true) // 通过ref打点调用toggleRowSelection方法，第二个必须为true
          i++
        }
        this.lists = this.exportWorkOrderIdList
      } else {
        this.origin = row.index // 没按住记录起点或没选起点
        this.lists = []
      }
    },
    closeDialog (e) {
      this.audioBlock = e
    },
    // 获取列表搜索配置
    getSearchOption () {
      let valueArray = {}
      let totalField = this.basicField.concat(this.advanceField)
      for (var i in totalField) {
        if (totalField[i].type === 'select' || totalField[i].type === 'cascader') {
          valueArray[totalField[i].prop] = this[totalField[i].prop + '_list']
        }
      }
      if (!window.FilterFuns) {
        this.searchBasicOption = {}
        this.searchAdvanceOption = []
      } else {
        this.searchBasicOption = window.FilterFuns.basicFilterOption(valueArray, this.form)
        this.searchAdvanceOption = window.FilterFuns.advanceFilterOption(valueArray, this.form).column
      }
    },
    // 获取配置字段方法
    getCustomField () {
      let totalField = this.basicField.concat(this.advanceField)
      // var FieldSourderArr = FilterFuns.valueArr
      for (var i in totalField) {
        if (totalField[i].type === 'select' || totalField[i].type === 'cascader') {
          this.getSourceFun(totalField[i].prop)
        }
      }
    },
    // 获取搜索处下拉/级联数据源
    getSourceFun (code) {
      switch (code) {
        case 'workOrderStatusId': this.getSelectAllWorkOrderStatusName(code)
          break;
        case 'handle_institution': this.selectAlllInfoFun(code, "dept")
          break;
        default: this.getSelectFieldList(code)
          break;
      }
    },
    checked (nu) {
      let urls = window.CONFIG.crUrl
      if (nu) {
        urls = urls + '?consNo=' + nu
      }
      window.parent.parent.open(urls, '_blank')
    },
    // 调取部门数据
    getSecondDataList (val) {
      this.current_handler_name.value = "";
      this.userValueList = this.selectAlllInfoFun('', val);
    },
    selectAlllInfoFun (code, val) {
      // 同步
      if (!code) {
        if (val === "user") {
          return window.CONFIG.selectAllInfo.userList;
        } else if (val === "role") {
          return window.CONFIG.selectAllInfo.roleList;
        } else if (val === "dept") {
          return window.CONFIG.selectAllInfo.deptList;
        } else if (val === "all") {
          return []
        }
      }
      //异步
      setTimeout(() => {
        if (val === "user") {
          this[code + '_list'] = window.CONFIG.selectAllInfo.userList;
        } else if (val === "role") {
          this[code + '_list'] = window.CONFIG.selectAllInfo.roleList;
        } else if (val === "dept") {
          this[code + '_list'] = window.CONFIG.selectAllInfo.deptList;
        } else if (val === "all") {
          this[code + '_list'] = []
        }
      }, 0);
    },
    advancedFilterData () {
      let params = {
        workOrderFilterMenuId: this.orderItem.id
      };
      advancedFilterData(params).then(res => {
        this.orderOption.column = res.data.data;
        this.orderOption.column.forEach(item => {
          delete item.type;
          item.overHidden = true;
          switch (item.prop) {
            case "create_time":
              item["searchRange"] = true;
              item["valueFormat"] = "yyyy-MM-dd HH:mm:ss";
              break;
          }
          if (
            item.type == "checkbox" ||
            item.type == "radio" ||
            item.type == "select" ||
            item.type == "cascader"
          ) {
            if (item.prop == "status_id" || item.prop == "work_order_type_id") {
              item.prop = item.prop + "";
            } else {
              item.prop = item.prop + "_label";
            }
          }
        });
      });
    },
    //高级筛选字段
    advanceFilterFun () {
      let valueArray = {}
      for (var i in this.advanceField) {
        if (this.advanceField[i].type === 'select' || this.advanceField[i].type === 'cascader') {
          valueArray[this.advanceField[i].prop] = this[this.advanceField[i].prop + '_list']
        }
      }
      // // FilterFuns.advanceFilterOption(valueArray, this.form).column
      // // if (this.advanceFilter.length <= 0) {
      //   this.advanceFilter = FilterFuns.advanceFilterOption(valueArray, this.form).column
      // // } else {
      // //   this.advanceFilter = []
      // // }
      this.searchAdvanceOption.forEach(item => {
        if (item.display === true) {
          item.display = false
        } else {
          item.display = true
        }
      })
    },
    filterChange (val) {
      this.advanceFilterData = val;
      this.handleSearch();
    },
    getSelectFieldList (code) {
      let _this = this;
      selectByCode(code).then(res => {
        if (res.data.retCode === 200) {
          let datas = res.data.data
          if (datas.length > 0 && !datas[0].label) {
            datas.forEach(item => {
              item.label = item.value
            })
          }
          _this[code + '_list'] = datas
        }
      });
    },
    // 点击合并工单跳转页面
    mergeOrder () {
      if (this.exportWorkOrderIdList < 1) {
        this.$message({
          message: "请选择要合并的数据",
          type: "error"
        });
        return;
      }
      this.$store.commit("orderTitleFun", "合并");
      this.$emit("hadleFormdetails", '合并', this.exportWorkOrderIdList.join(','));
      // this.$router.push({
      //   name: "createForm",
      //   params: {
      //     list: this.exportWorkOrderIdList,
      //     typeData: 3
      //   }
      // });
    },
    closeSelect () {
      if (this.selectAllIdLength === 0) {
        this.$message({
          message: "请选择操作项",
          type: "error"
        });
      } else {
        this.$confirm("工单关闭后，未流转的工单将停止流转", "确认关闭工单", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          center: true,
          customClass: "messageBox-prompt-delete"
        }).then(() => {
          let params = {
            idList: this.exportWorkOrderIdList,
            userId: this.$store.state.userId
          };
          closeBatch(params)
            .then(res => {
              if (res.data.retCode === 200) {
                this.$message({
                  type: "success",
                  message: "关闭成功!"
                });
                this.handleSearch();
                this.advancedFilterData();
                this.selectAllIdLength = 0;
              }
            })
            .catch(error => {
              console.log(error);
            });
        });
      }
    },
    // 根据类型id查询用户列表
    getUserListByWorkOrderTypeNodeIdInfo (id) {
      getUserListByWorkOrderTypeNodeId(id).then(res => {
        if (res.data.retCode === 200) {
          this.forms.userOptions = res.data.data;
        }
      });
    },
    // 重置筛选信息
    resart () {
      for (let i in this.form) {
        this.form[i] = "";
      }
      for (let j in this.current_handler_name) {
        this.current_handler_name[j] = "";
      }
    },
    // 导出
    exportOrder () {
      let params = {
        workOrderIdList: this.exportWorkOrderIdList,
        workOrderSelectInputDto: {
          currentPage: this.orderPage.page, // 当前页
          field: this.field, // 排序
          sortTag: this.sortTag, // 排序 0 1 切换
          pageSize: this.orderPage.pageSize, // 每页数量
          workOrderFilterId: Number(this.orderItem.id), // 点击的工单流程id
          userId: this.$store.state.userId, // 当前用户
          createTime: this.form.createTime || [], // 创建时间
          workOrderStatusId: this.form.workOrderStatusId, // 工单状态
          customField: this.customField
        }
      };
      writeWithHead(params).then(res => {
        if (res.status === 200) {
          this.$message({
            type: "success",
            message: "导出成功"
          });
          const blob = new Blob([res.data]);
          const fileName = "导出文件.xlsx"; //下载文件名称
          const elink = document.createElement("a");
          elink.download = fileName;
          elink.style.display = "none";
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        } else {
          this.$message({
            type: "error",
            message: "导出失败"
          });
        }
      });
    },
    //* ***开始**** 下载base64文件流代码
    // dataURLtoBlob (dataurl, filename) {
    //   let arr = dataurl.split(",");
    //   let mime = arr[0].match(/:(.*?);/)[1];
    //   let bstr = atob(arr[1]);
    //   let n = bstr.length;
    //   let u8arr = new Uint8Array(n);
    //   while (n--) {
    //     u8arr[n] = bstr.charCodeAt(n);
    //   }
    //   return new Blob([u8arr], { type: mime });
    // },
    // downloadFile (url, name = "导出列表") {
    //   var a = document.createElement("a");
    //   a.setAttribute("href", url);
    //   a.setAttribute("download", name);
    //   a.setAttribute("target", "_blank");
    //   let clickEvent = document.createEvent("MouseEvents");
    //   clickEvent.initEvent("click", true, true);
    //   a.dispatchEvent(clickEvent);
    // },
    // downloadFileByBase64 (base64, name) {
    //   let myBlob = this.dataURLtoBlob(base64);
    //   let myUrl = URL.createObjectURL(myBlob);
    //   this.downloadFile(myUrl, name);
    // },
    //* ***结束**** 下载base64文件流代码
    // 获取工单状态列表
    getSelectAllWorkOrderStatusName (code) {
      let _this = this
      selectAllWorkOrderStatusName().then(res => {
        if (res.data.retCode === 200) {
          _this[code + '_list'] = res.data.data
        }
      });
    },
    // 获取工单流程
    getWorkOrderType (code) {
      let _this = this
      selectAllWorkOrderTypeName().then(res => {
        if (res.data.retCode === 200) {
          _this[code + '_list'] = res.data.data
        }
      });
    },
    orderDetails (val) {
      this.$store.commit("orderDetailsIdFun", val.id); // 工单编号的id
      this.$emit("hadleFormdetails", val.id);
      // this.$router.push("/formDetails/" + this.$store.state.orderDetailsId);
    },
    handleSearch () {
      this.orderPage.page = 1;
      this.$refs.multipleTable && this.$refs.multipleTable.selectClear && this.$refs.multipleTable.selectClear()
      this.handleSearchData();
    },
    // 根据条件查询table表格数据
    handleSearchData () {
      let hignParamsArr = [];
      this.tableData = [];
      let highParams = {
        create_time: this.form.createTime || [], // 创建时间
        status_id: this.form.workOrderStatusId, // 工单状态
        id: this.form.workOrderId // 工单编号
      };
      // 定制字段
      let totalField = this.basicField.concat(this.advanceField)
      let customField = {}
      for (var i in totalField) {
        if (window.CONFIG.itemType == "2" && totalField[i].prop == 'createUser') { //锦程
          customField['create_user_name'] = this.form[totalField[i].prop]
        } else if (!(totalField[i].prop == 'createTime' || totalField[i].prop == 'workOrderId' || totalField[i].prop == 'workOrderStatusId')) {
          customField[totalField[i].prop] = this.form[totalField[i].prop] || ''
        }
      }
      delete customField['undefined']
      Object.assign(highParams, customField);
      for (var y in highParams) {
        let itemArr = [];
        if (highParams[y]) {
          if (y === "create_time" || y === "handle_institution") {
            itemArr[0] = y;
            itemArr[1] = "=";
            itemArr[2] = highParams[y] || [];
          } else {
            itemArr[0] = y;
            itemArr[1] = "like";
            itemArr[2] =
              typeof highParams[y] == "string"
                ? highParams[y].trim()
                : highParams[y];
          }
          hignParamsArr.push(itemArr);
        }
      }
      let params = {
        // 基础参数
        currentPage: this.orderPage.page, // 当前页
        pageSize: this.orderPage.pageSize, // 每页数量
        userId: this.$store.state.userId, // 当前用户
        workOrderFilterId: Number(this.orderItem.id), // 点击的工单流程id
        // 特殊定制
        current_handler_name: {
          type: this.current_handler_name.type,
          value:
            this.current_handler_name.type == "dept"
              ? this.current_handler_name.value.length > 0
                ? [common.deepClone(this.current_handler_name.value)]
                : []
              : this.current_handler_name.value.length > 0
                ? [this.current_handler_name.value]
                : []
        },
        // 高频+高级筛选
        advancedSelect: this.advanceFilterData.concat(hignParamsArr)
      };

      let _this = this;
      getSelect(params).then(res => {
        let data = res.data;
        // this.advanceFilterData = []
        if (data.retCode === 200) {
          _this.tableData = data.data;
          // 将自定义字段中的字段合并到第一层
          for (var i = 0; i < _this.tableData.length; i++) {
            _this.tableData[i].workOrderType =
              _this.tableData[i].workOrderTypeName;
            _this.customField = _this.tableData[i].customField;
            _this.tableData[i].customField_label = {
              file_label: "name.txt"
            };
            Object.assign(
              _this.tableData[i],
              _this.tableData[i].customField,
              _this.tableData[i].customField_label
            );
          }
          _this.tableData.forEach(item => {
            for (var x in item) {
              switch (x) {
                case "workOrderTypeName":
                  item["work_order_type_id"] = item.workOrderTypeName;
                  break;
                case "createTime":
                  item["create_time"] = item.createTime;
                  break;
                case "createUserName":
                  item["create_user_name"] = item.createUserName;
                  break;
                case "statusName":
                  item["status_id"] = item.statusName;
                  break;
                case "currentHandlerName":
                  item["current_handler_name"] = item.currentHandlerName;
                  break;
                case "isTimeOut":
                  item["is_time_out"] = item.isTimeOut;
                  break;
                case "closeTime":
                  item["close_time"] = item.closeTime;
                  break;
                case "urgeCount":
                  item["urge_count"] = item.urgeCount;
                  break;
                default:
                  x = item.x;
              }
            }
          });
          _this.currentWorkOrderNodeId = "";
          // 当前过滤器下的工单流程id标识 用来调取流程模板
          for (var x = 0; x < data.data.length; x++) {
            if (data.data[x].currentWorkOrderNodeId) {
              _this.currentWorkOrderNodeId =
                data.data[0].currentWorkOrderNodeId;
            }
          }
          _this.orderPage.total = data.count;
          _this.allWorkOrderIdList = [];
          for (var y = 0; y < data.data.length; y++) {
            _this.allWorkOrderIdList.push(data.data[y].id);
          }
          setTimeout(() => {
            _this.loading = false;
          }, 1000);
          _this.origin = -1
          _this.tableData.forEach((item, index) => {// 遍历索引,赋值给data数据
            item.index = index
          })
          // _this.$refs.multipleTable.selectClear && _this.$refs.multipleTable.selectClear()
        } else {
          _this.$message({
            type: "error",
            message: res.data.msg
          });
        }
      });
    },
    cancelTransfer () {
      this.transferShow = false;
    },
    changeDate () { },
    createForm (val) {
      this.$store.commit("orderTypeIdFun", this.$store.state.orderTypeId);
      this.$store.commit("orderTitleFun", val); // 主标题
      sessionStorage.setItem("workOrderIdList", JSON.stringify("")); // 新建工单的时候清空id
      this.$store.commit("orderDetailsIdFun", ""); // 新建工单的时候清空id
      // this.$router.push({
      //   name: "createForm",
      //   params: {
      //     typeData: 3
      //   }
      // });
      this.$emit("hadleFormdetails", val);
    },
    handleSizeChange (pageSize) {
      this.orderPage.pageSize = pageSize;
      this.orderPage.page = 1;
      this.handleSearchData();
    },
    handleCurrentChange (page) {
      this.orderPage.page = page;
      this.handleSearchData();
    },
    // 删除
    deleteSelect () {
      if (!this.selectAllIdLength > 0) {
        this.$message({
          message: "请选择删除项",
          type: "error"
        });
      } else {
        this.$confirm("确认要删除吗？", "确认删除", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          center: true,
          customClass: "messageBox-prompt-delete"
        }).then(() => {
          let params = {
            idList: this.exportWorkOrderIdList,
            userId: this.$store.state.userId
          };
          deleteBatch(params).then(res => {
            if (res.data.retCode === 200) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.handleSearch();
              this.advancedFilterData();
              this.selectAllIdLength = 0;
            }
          });
        });
      }
    },
    // 选择相对应编号的数据
    handleSelectionChange (val) {
      this.multipleSelection = val;
      this.selectAllIdLength = val.length;
      this.exportWorkOrderIdList = [];
      for (var i = 0; i < this.multipleSelection.length; i++) {
        // 所有状态的工单列表
        this.exportWorkOrderIdList.push(this.multipleSelection[i].id);
      }
      this.changeLists = this.exportWorkOrderIdList
    },
    change () { },
    // 播放录音文件
    playAudio (id) {
      this.voiceDataInfo.voiceKeyId = id
      let params = {
        callUUID: this.voiceDataInfo.voiceKeyId
      }
      if (this.voiceDataInfo.voiceKeyId && this.voiceDataInfo.voiceKeyId !== '') {
        this.audioBlock = true
        this.audioNone = true
        this.$refs.audioMP3.getVoiceInfo(params)
      } else {
        this.$message({
          type: "fail",
          message: "无语音文件!"
        });
      }
    }
  }
};
</script>
<style scoped>
.paging-foot {
  padding: 20px 0;
}

>>> .el-range-separator {
  width: 6%;
}

>>> .default {
  background: transparent;
  border: none;
}

.btn30-default,
.export {
  color: black;
  background: #f5f6fa;
  margin-left: 20px;
}

>>> .el-icon--right {
  color: #2393f1;
}

.el-row {
  line-height: 30px;
}

.el-divider--horizontal {
  margin: 20px 0;
}

.el-row > .font-weight {
  font-weight: bold;
  color: #231815;
  font-size: 13px;
}

.select-number {
  color: #b50029;
}

>>> .el-date-editor .el-range-separator {
  padding: 0;
  margin: 0 5px;
}

.el-header-content {
  margin-bottom: 20px;
  line-height: 40px;
}
>>> .el-input__inner {
  min-width: 100%;
}

.item {
  margin-top: 10px;
}

>>> .el-badge__content.is-fixed {
  background-color: #f78c35;
  line-height: 15px;
}

/* >>> .el-input__icon {
  color: #2594f2;
  font-weight: bold;
} */

.order_num {
  white-space: pre-wrap;
  text-decoration: underline;
  cursor: pointer;
  color: #4786c3;
}
>>> .el-badge__content.is-fixed {
  top: 3px;
  right: 36px;
}
/* avue */
>>> .el-form-item__label {
  white-space: nowrap;
  text-align: left;
}

>>> .avue-form__menu--center {
  display: none;
}
.searchBtn {
  margin-bottom: 20px;
  margin-left: 15px !important;
}
>>> .avue-group__item {
  padding: 0;
}
>>> .avue-crud__tip {
  display: none;
}
>>> .el-table__empty-block {
  width: 100%;
}
>>> .avue-crud__menu {
  display: none;
}
</style>
